package com.ebelter.temperature.activitys;


import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;
import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.common.Constants;
import com.ebelter.btcomlib.utils.StatusBarUtil;
import com.ebelter.btcomlib.utils.UserSpUtil;
import com.ebelter.btcomlib.utils.activity_manager.ActivityManagers;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.btcomlib.views.dialogs.TextTipDialog;
import com.ebelter.temperature.R;

import static com.ebelter.temperature.activitys.T_ModifyNameActivity.T_ModifyNameActivity_REQUEST_CODE;

public class T_AcountInfoActivity extends BaseActivity {

    private static final String TAG="T_AcountInfoActivity";


    TextView topTitleTv;
    TextView nickname_tv;//昵称
    TextView email_tv;//邮箱

    @Override
    protected int loadLayoutById() {
        return R.layout.activity_t_acountinfo;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        StatusBarUtil.setColor(this, Color.parseColor("#787ede"));
        topTitleTv = findViewById(R.id.top_title_tv);
        nickname_tv = findViewById(R.id.nickname_tv);
        email_tv = findViewById(R.id.email_tv);

    }

    @Override
    protected void initData() {
        topTitleTv.setText("账户信息");

        nickname_tv.setText(UserSpUtil.readString(Constants.IUser.NICK_NAME));
        email_tv.setText(UserSpUtil.readString(Constants.IUser.EMAIL));

    }

    //返回键被按下
    public void backClick(View view){
        LogUtils.i(TAG,"返回键被按下");
        finish();
    }


    //修改密码
    public void modify_psw_rl(View view){
        LogUtils.i(TAG,"modify_psw_tvClick");
        startActivity(T_VerificEmailCodeActivity.class);

    }


    //退出登录
    public void log_outClick(View view){
        LogUtils.i(TAG,"log_outClick");

        TextTipDialog loginout=new TextTipDialog(this,"确定要退出登录吗?");

        loginout.setListener(new TextTipDialog.ICancelOkBtListener() {
            @Override
            public void cancel(Dialog dialogView) {
                dialogView.cancel();
            }

            @Override
            public void ok(Dialog dialogView) {
                UserSpUtil.removeAll();
                startActivity(T_LoginActivity.class);
                ActivityManagers.getInstance().closeActivity(T_SettingActivity.TAG+":"+T_MainActivity.TAG);
                finish();
            }
        });
        loginout.show();



    }


    //修改昵称的相对布局被按下
    public void name_rl_Click(View view){

        Intent intent=new Intent(this,T_ModifyNameActivity.class);
        startActivityForResult(intent, T_ModifyNameActivity_REQUEST_CODE);
    }

    //修改邮箱的相对布局被按下
    public void email_rl_Click(View view){

        // Intent intent=new Intent(this,BPM_ModifyNameActivity.class);
        // startActivityForResult(intent,BPM_ModifyNameActivity.BPM_ModifyNameActivity_REQUEST_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

       //更新一下名字的意思
        if (resultCode==resultCodeSuccess&&requestCode==T_ModifyNameActivity_REQUEST_CODE){
            nickname_tv.setText(UserSpUtil.readString(Constants.IUser.NICK_NAME));
        }



    }
}
